<!DOCTYPE html>
<html lang="zh-CN">
  <head>
	  <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'添加', styles:'bootstrap,font-awesome,animate,style,dtvalidate,layui,cxwebuploader,cxuploader,chosen,fancybox,layui'}){%>
	  <style type="text/css">
		  body{padding-top:10px;}
		  .radio{
			  vertical-align:middle;
			  margin-top:5px;
		  }
	  </style>
	  <%}%>
  </head>
  <body>
  <div class="wrapper wrapper-content">
	  <div class="row">
		  <div class="col-sm-12">
			  <div class="col-sm-offset-1 col-sm-10" style="margin-left: -10px;width: 100%;">
				  <button type="button" class="return-btn btn btn-w-m btn-primary">返回</button>
				  <div style="border-color: #e7eaec;border-image: none;border-style: solid solid none;border-width: 4px 0px;padding-bottom: 15px;margin-top: 10px;" ></div>
			  </div>
		  </div>
	  </div>
  </div>
	<!-- START 内容部分 -->
	<div class="container">
		<form class="form-horizontal" id="info-form" method="post" autocomplete="off">
			<div class="form-group">
				<label class="col-sm-2 control-label text-right">SKU:</label>
				<div class="col-sm-8">
					<input type="text" id="productSku" name="productSku" onkeyup="this.value=this.value.toLocaleUpperCase()" class="form-control" />
				</div>
			</div>
			<div class="form-group">
				<label class="control-label col-sm-2">产品名称:</label>
				<div class="col-sm-8">
					<input type="text" id="productName" name="productName" class="form-control"  />
				</div>
			</div>
			<div class="form-group">
				<label class="control-label col-sm-1 col-sm-offset-1">所属品类:</label>
					<div class="col-sm-2">
						<select id="productBigClassId" name="productBigClassId"  class="form-control">
							<option value="">全部分类</option>
							<%for(var category in category){%>
							<option value="${category.id}"  >${category.categoryName}</option>
							<%}%>
						</select>
						<input type="hidden" name="productBigClassName" id="productBigClassName">
					</div>
				<div class="col-sm-2">
					<select id="productMidClassId" name="productMidClassId" class="form-control">
						<option value="">全部分类</option>
					</select>
					<input type="hidden" name="productMidClassName" id="productMidClassName">
				</div>.
				<div class="col-sm-4">
					<select id="productClassId" name="productClassId" class="form-control">
						<option value="">全部分类</option>
					</select>
					<input type="hidden" name="productClassName" id="productClassName">
				</div>
			</div>


			<div class="form-group">
				<label class="col-sm-2 control-label">尺码(CM):</label>
				<div class="col-sm-3">
					<input type="text" id="productCm" name="productCm" class="form-control"  />
				</div>
				<label class="col-sm-1 control-label">INCH:</label>
				<div class="col-sm-4">
					<input type="text" id="productInch" name="productInch" class="form-control"  />
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-2 control-label">毛重(KG):</label>
				<div class="col-sm-3">
					<input type="text" id="productGrossWeight" name="productGrossWeight" class="form-control"  onkeyup="value=value.replace(/[^\d\.]/g,'')" />
				</div>
				<label class="col-sm-1 control-label">净重(KG):</label>
				<div class="col-sm-4">
					<input type="text" id="productWeight" name="productWeight" class="form-control"  onkeyup="value=value.replace(/[^\d\.]/g,'')" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">外箱整重(KG):</label>
				<div class="col-sm-3">
					<input type="text" id="productOutBoxWeight" name="productOutBoxWeight" class="form-control"  onkeyup="value=value.replace(/[^\d\.]/g,'')" />
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-2 control-label">商品颜色:</label>
				<div class="col-sm-3">
					<select  id="productColorId" name="productColorId" xm-select="productColorId" xm-select-radio xm-select-search>
						<%for(var dict in color){%>
						<option value="${dict.detailCode}">${dict.detailName}</option>
						<%}%>
					</select>
					<input type="hidden" id="productColorName" name="productColorName">
				</div>
				<label class="col-sm-1 control-label">商品属性:</label>
				<div class="col-sm-4">
					<select id="productPropertyId" name="productPropertyId" class="form-control col-sm-2">
						<option value="">全部分类</option>
						<%for(var dict in property){%>
						<option value="${dict.detailCode}">${dict.detailName}</option>
						<%}%>
					</select>
					<input type="hidden" id="productPropertyName" name="productPropertyName">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">装箱量:</label>
				<div class="col-sm-3">
					<input type="text" id="productPackageNumber" name="productPackageNumber" class="form-control" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" />
				</div>
				<label class="col-sm-1 control-label">内含件数:</label>
				<div class="col-sm-4">
					<input type="text" id="productContainCount" name="productContainCount" class="form-control"  onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">尺码:</label>
				<div class="col-sm-3">
					<select id="productSizeId" name="productSizeId" class="form-control col-sm-2">
						<option value="">全部分类</option>
						<%for(var dict in size){%>
						<option value="${dict.detailCode}">${dict.detailName}</option>
						<%}%>
					</select>
					<input type="hidden" id="productSizeName" name="productSizeName">
				</div>
				<label class="col-sm-1 control-label">单位:</label>
				<div class="col-sm-4">
					<select id="productUnit" name="productUnit" class="form-control col-sm-2">
						<option value="">全部分类</option>
						<%for(var dict in unit){%>
						<option value="${dict.detailName}">${dict.detailName}</option>
						<%}%>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label text-right">HS CODE:</label>
				<div class="col-sm-3">
					<input type="text" id="productCode" name="productCode"  class="form-control" />
				</div>
				<label class="col-sm-1 control-label text-right">生产周期:</label>
				<div class="col-sm-4">
					<input type="text" id="productDay" name="productDay" onkeyup="value=value.replace(/[^\d?.{1}\d{2}]/g,'')" class="form-control" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label text-right">门幅:</label>
				<div class="col-sm-3">
					<input type="text" id="productFabric" name="productFabric"  class="form-control" />
				</div>
				<label class="col-sm-1 control-label text-right">材质:</label>
				<div class="col-sm-4">
					<input type="text" id="productMaterial" name="productMaterial" class="form-control" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label text-right">报关名称:</label>
				<div class="col-sm-8">
					<input type="text" id="productDeclarationName"  name="productDeclarationName"  class="form-control" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label text-right">UPC:</label>
				<div class="col-sm-8">
					<input type="text" id="productUpc"  name="productUpc"  class="form-control" />
				</div>
			</div>
			<div style="border-color: #e7eaec;border-image: none;border-style: solid solid none;border-width: 4px 0px;padding-bottom: 15px;" ></div>
			<div class="form-group">
				<label class="col-sm-2 control-label text-right">内包装&nbsp;&nbsp;&nbsp;&nbsp;长(CM):</label>
				<div class="col-sm-2">
					<input type="text" id="productLength" name="productLength"  onkeyup="value=value.replace(/[^\d\.]/g,'')" class="form-control" />
				</div>
				<label class="col-sm-1 control-label text-right">宽(CM):</label>
				<div class="col-sm-2">
					<input type="text" id="productWidth" name="productWidth"  onkeyup="value=value.replace(/[^\d\.]/g,'')" class="form-control" />
				</div>
				<label class="col-sm-1 control-label text-right">高(CM):</label>
				<div class="col-sm-2">
					<input type="text" id="productHeight" name="productHeight"  onkeyup="value=value.replace(/[^\d\.]/g,'')" class="form-control" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label text-right">外包装&nbsp;&nbsp;&nbsp;&nbsp;长(CM):</label>
				<div class="col-sm-2">
					<input type="text" id="productOutBoxLength" name="productOutBoxLength"  onkeyup="value=value.replace(/[^\d\.]/g,'')"class="form-control" />
				</div>
				<label class="col-sm-1 control-label text-right">宽(CM):</label>
				<div class="col-sm-2">
					<input type="text" id="productOutBoxWidth" name="productOutBoxWidth"  onkeyup="value=value.replace(/[^\d\.]/g,'')" class="form-control" />
				</div>
				<label class="col-sm-1 control-label text-right">高(CM):</label>
				<div class="col-sm-2">
					<input type="text" id="productOutBoxHeight" name="productOutBoxHeight"  onkeyup="value=value.replace(/[^\d\.]/g,'')" class="form-control" />
				</div>
			</div>
			<div style="border-color: #e7eaec;border-image: none;border-style: solid solid none;border-width: 4px 0px;padding-bottom: 15px;" ></div>
			<div class="form-group">
				<label class="col-sm-2 control-label text-right">英文品名:</label>
				<div class="col-sm-2">
					<input type="text" id="productCnName" name="productCnName" class="form-control" />
				</div>
				<label class="col-sm-1 control-label text-right">中文品名:</label>
				<div class="col-sm-2">
					<input type="text" id="productEnName" name="productEnName"  class="form-control" />
				</div>
				<label class="col-sm-1 control-label text-right">成分:</label>
				<div class="col-sm-2">
					<input type="text" id="productComposition" name="productComposition"   class="form-control" />
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<button type="button" class="save-btn btn btn-primary">
						<i class="fa fa-save"></i> 保存
					</button>
				</div>
			</div>


		</form>
	</div>
	<!-- END 内容部分 -->
  </div>
	<!-- START 公共脚本 -->
    <%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,dtvalidate,dtvalidate-lang-zh_cn,laydate,layer,chosen,chosen-demo,upload,imgbox,upload,layui'}){}%>
	<!-- END 公共脚本 -->
	<script>
        //执行一个laydate实例
        laydate.render({
            elem: '#birth' //指定元素
        });
	</script>


	<script>
		layui.use('upload', function(){
			var upload = layui.upload;
			upload.render({
				elem: '#import-btn', //绑定元素,
				accept:'file',
				url: '/sea/product/product/importImg/', //上传接口
				data:{},
				before:function () {
					layer.load(1, {
						shade: [0.1,'#fff'] //0.1透明度的白色背景
					});
				}
				,done: function(data){
					if( data.ok ){
						layer.msg(data.msg,{icon: 1,time: 1500},function(){
							//刷新页面

							$("#imgBox").show();
							$("#imgUrl").attr('src',data.data);
							$(".fancybox").attr('href',data.data);
							$("#productImg").val(data.data);
							layer.closeAll();
						});
					}else{
						layer.msg(data.msg,{icon: 0,time: 5000},function () {
							layer.closeAll();
						});

					}
				}
				,error: function(){
					//请求异常回调
					layer.closeAll();
				}
			});
		});
	var cvalidator;
	$(function(){
		$("#imgBox").hide();
		$('.fancybox').fancybox({
			openEffect: 'none',
			closeEffect: 'none'
		});
		//初始化验证器
		cvalidator = $.fn.dlshouwen.validator.init($('#info-form'));
		//提交表单
		$('.save-btn').on('click',function(){

			var productColorId=$('#productColorId').val();
			if(productColorId==''){
				parent.layer.msg('请选择颜色！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
				return;
			}else{
				$("#productColorName").val(formSelects.value('productColorId', 'nameStr'));
			}
			var productBigClassId=$("#productBigClassId").val();
			if(productBigClassId=='') {
				parent.layer.msg('请选择大类！', {icon: 0, time: 1500, shade: [0.8, '#393D49']});
				return;
			}else{
				$("#productBigClassName").val($("#productBigClassId  option:selected").text());
			}
			var productMidClassId=$("#productMidClassId").val();
			if(productMidClassId=='') {
				parent.layer.msg('请选择中类！', {icon: 0, time: 1500, shade: [0.8, '#393D49']});
				return;
			}else{
				$("#productMidClassName").val($("#productMidClassId  option:selected").text());
			}
			var productClassId=$("#productClassId").val();
			if(productClassId=='') {
				parent.layer.msg('请选择小类！', {icon: 0, time: 1500, shade: [0.8, '#393D49']});
				return;
			}else{
				$("#productClassName").val($("#productClassId  option:selected").text());
			}

			var productPropertyId=$("#productPropertyId").val();
			if(productPropertyId !=''){
				$("#productPropertyName").val($("#productPropertyId  option:selected").text());
			}

			var productSizeId=$("#productSizeId").val();
			if(productSizeId !=''){
				$("#productSizeName").val($("#productSizeId  option:selected").text());
			}
			var productOutBoxLength=$("#productOutBoxLength").val();
			var productOutBoxWidth=$("#productOutBoxWidth").val();
			var productOutBoxHeight=$("#productOutBoxHeight").val();
			if(productOutBoxLength=='' || productOutBoxWidth=='' || productOutBoxHeight==''){
				parent.layer.msg('外箱长宽高不能为空！', {icon: 0, time: 1500, shade: [0.8, '#393D49']});
				return;
			}
			//数据提交
			$.post('/sea/product/product/save.do',$('#info-form').serialize(),function(data){
				if( data.ok ){
					parent.layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']}, function(){
						parent.$productTable.bootstrapTable('refresh');
						parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭弹窗
					});
				}else{
					parent.layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
				}
			});
		});



    });



	$("#productBigClassId").change(function () {
		var parentId=$("#productBigClassId").val();
		getCategory(parentId,1);
	});
	$("#productMidClassId").change(function () {
		var parentId=$("#productMidClassId").val();
		getCategory(parentId,2);
	});

	function getCategory(parentId,type) {
		$.ajax({
			url:'/sea/product/category/findByParentId',
			data:{
				id:parentId
			},
			type:'post',
			success:function (data) {
				var list=data;
				if(list.length>0){
					var category='<option value="">全部分类</option>';
					for(var i=0;i<list.length;i++){
						category+='<option value="'+list[i].id+'">'+list[i].categoryName+'</option>';
					}
					if(type=='1') {
						$("#productMidClassId").html(category);
					}
					if(type=='2'){
						$("#productClassId").html(category);
					}
				}
			}
		});
		//返回

	}
	$('.return-btn').on('click',function(){
		parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭弹窗
	});
    </script>
  </body>
</html>